<?php
/**
 * Custom exception class definitions
 *   
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MutantVole
 */
     
/**
 * Thrown when an attempt is made to read a write-only property
 * @package MutantVole
 * @subpackage Exceptions
 */    
class WriteOnlyPropertyException extends Exception {
	
	public function __construct($class, $name) {
		parent::__construct("{$class}::{$name} is a write-only property");
	}
}

/**
 * Thrown when an attempt is made to write a read-only property
 * @package MutantVole
 * @subpackage Exceptions
 */    
class ReadOnlyPropertyException extends Exception {
	
	public function __construct($class, $name) {
		parent::__construct("{$class}::{$name} is a read-only property");
	}
}

/**
 * Thrown when an attempt is made to access a property that is inaccessible or does not exist
 * @package MutantVole
 * @subpackage Exceptions
 */    
class InaccessiblePropertyException extends Exception {
	
	public function __construct($class, $name) {
		parent::__construct("{$class}::{$name} is inaccessible");
	}
}

/**
 * Thrown when loading a class by name fails because the class does not exist
 * @package MutantVole
 * @subpackage Exceptions
 */  
class ClassNotFoundException extends Exception {
	
	public function __construct($class) {
		parent::__construct("Class {$class} cannot be found");
	}	
}

/**
 * Base class for Contract exceptions
 * @package MutantVole
 * @subpackage Exceptions
 */  
class ContractException extends Exception {}

/**
 * Thrown when a Contract::Precondition fails
 * @package MutantVole
 * @subpackage Exceptions
 */  
class PreconditionFailedException extends ContractException {
	
	public function __construct($message) {
		parent::__construct("Precondition Failed: $message");
	}
}

/**
 * Thrown when a Contract::Postcondition fails
 * @package MutantVole
 * @subpackage Exceptions
 */ 
class PostconditionFailedException extends ContractException {
	
	public function __construct($message) {
		parent::__construct("Postcondition Failed: $message");
	}
}

/**
 * Thrown when a Contract::Invariant fails
 * @package MutantVole
 * @subpackage Exceptions
 */ 
class InvariantFailedException extends ContractException {

	public function __construct($message) {
		parent::__construct("Invariant Failed: $message");
	}
}

/**
 * Thrown when a Contract::Assertion fails
 * @package MutantVole
 * @subpackage Exceptions
 */ 
class AssertionFailedException extends ContractException {

	public function __construct($message) {
		parent::__construct("Assertion Failed: $message");
	}
}

/**
 * Thrown when the dependency injector tries to get an instance of an unbound abstract class
 * @package MutantVole
 * @subpackage Exceptions
 */ 
class UnboundDependencyException extends Exception {
	
	public function __construct($abstract, $namespace) {
		parent::__construct("Class $abstract not bound to concrete class in namespace $namespace");
	}
}

/**
 * Thrown when a request is made for a page that does not exist in the app
 * @package MutantVole
 * @subpackage Exceptions
 */ 
class PageNotFoundException extends Exception {
	
	public function __construct($mod, $page) {
		parent::__construct("Page /{$mod}/{$page} could not be found");
	}
}

/**
 * Thrown when a Page object tries to render, but has no iViewRenderer specified
 * @package MutantVole
 * @subpackage Exceptions
 */ 
class PageMissingRendererException extends Exception {
	
	public function __construct($pageClass) {
		parent::__construct("{$pageClass} has no renderer");
	}
}

/**
 * Thrown when the Setting class cannot load the setting file
 * @package MutantVole
 * @subpackage Exceptions
 */   
class SettingsFileNotFoundException extends Exception {
	
	public function __construct($filename) {
		parent::__construct("Cannot find settings file $filename");
	}
}

/**
 * Thrown when a View renderer object cannot load its associated template file
 * @package MutantVole
 * @subpackage Exceptions
 */  
class RendererTemplateFileNotFoundException extends Exception {
	
	public function __construct($filename) {
		parent::__construct("Cannot find template file $filename");
	}
}

/**
 * Thrown when adding an invalid function or method to a Request object
 * @package MutantVole
 * @subpackage Exceptions
 */
class InvalidRequestHandlerException extends Exception {
    
	public function __construct($method, $class = null) {
		parent::__construct("Invalid request handler: ". $class ? "{$class}::" : '' ."{$method}");
	}
}

/**
 * Thrown when trying to open a file for writing or appending and fails
 * @package MutantVole
 * @subpackage Exceptions 
 */
class CannotOpenFileException extends Exception {
    
    public function __construct($filename) {
        parent::__construct("File {$filename} could not be opened for writing");
    }
}

/**
 * Thrown when trying to write to a file and fails
 * @package MutantVole
 * @subpackage Exceptions
 */
class FailedToWriteToFileException extends Exception {
    
    public function __construct($filename) {    	
        parent::__construct("Failed to write to file {$filename}");
    }
}


?>